<?
$sub_menu = "230300";
include_once("./_common.php");

auth_check($auth[$sub_menu], "w");

check_token();

$sql_common = "
ac_name = '$ac_name',
ac_hp = '$ac_hp',
ac_payment = '$ac_payment',
ac_paydate = '$ac_paydate',
ac_status = '$ac_status',
ac_memo = '$ac_memo',
ac_admin_memo = '$ac_admin_memo'";

if ($w == "") {
    $row = sql_fetch("select * from $g4[member_table] where mb_id = '$mb_id'");
    if (!$row)
	alert("회원ID 가 존재하지 않습니다.");

    sql_query("insert into $mw_cash[account_table] set mb_id = '$mb_id', $sql_common, ac_datetime = '$g4[time_ymdhis]', ac_tax = '$mw_cash[cf_tax]'");

    $ac_id = mysql_insert_id();

    $url = "mw.account.form.php?w=u&ac_id=$ac_id$qstr";
    $msg = "등록";
}
else if ($w == "u" && $ac_id) {
    $row = sql_fetch("select * from $mw_cash[account_table] where ac_id = '$ac_id'");
    if (!$row)
	alert("자료가 존재하지 않습니다.");

    sql_query("update $mw_cash[account_table] set $sql_common where ac_id = '$ac_id' ");

    $url = "mw.account.form.php?w=u&ac_id=$ac_id$qstr";
    $msg = "수정";
}
else if ($w == "d" && $ac_id) {
    sql_query("delete from $mw_cash[account_table] where ac_id = '$ac_id' ");

    $url = "mw.account.list.php?$qstr";
    $msg = "삭제";
}
else if ($w == "c" && $ac_id) {
    $row = sql_fetch("select * from $mw_cash[account_table] where ac_id = '$ac_id'");
    if (!$row)
	alert("자료가 존재하지 않습니다.");

    if ($row[ac_to_cash])
	alert("이미 충전되었습니다.");

    $msg = "충전";
    $mb_id = $row[mb_id];
    $cl_cash = mw_payment_to_cash($row[ac_payment], $row[ac_tax]);
    $cl_content = "[충전] 무통장(".number_format($row[ac_payment])."원)→{$mw_cash[cf_cash_name]}(".number_format($cl_cash)."{$mw_cash[cf_cash_unit]})";
    $cl_payment = $row[ac_payment];
    $cl_paytype = "무통장";
    $cl_paylog = "이름 : $row[ac_name]\n결제금액 : ".number_format($row[ac_payment])."원";
    $cl_admin_memo = ""; 

    $cl_id = mw_cash_charge($mb_id, $cl_cash, $cl_content, $cl_payment, $cl_paytype, $cl_paylog, $cl_admin_memo);

    sql_query("update $mw_cash[account_table] set ac_to_cash = '1', ac_status = '충전완료' where ac_id = '$ac_id'");
    $url = "mw.account.form.php?w=u&ac_id=$ac_id$qstr";
}

alert("$msg 되었습니다.", $url);
?>
